# coding: utf-8
from config.settings import database as db,get_autoincre_id
from datetime import datetime

def list(page=1,limit=5):
    d={}
    offset = (int(page)-1)*limit
    record_count=db.link.find({"lid":{"$gt":0}}).count()
    d['list']=db.link.find({"lid":{"$gt":0}}).sort("sort").limit(limit).skip(offset)
    return d

def remove(lid):
    pass

def save(data):
    if data.lid==0:
       data.lid=get_auto_id('link')
       return db.link.insert(data)
    else:
       return db.link.update({"lid":data.lid},{"$set":data})

def find_one(id):
    return db.link.find_one({"id":id})